<div class="layuimini-main">

    <div lay-filter="userForm" class="layui-form layuimini-form">
		<input id="pageParam" style="display: none" />
		<div class="layui-form-item hide">
            <label class="layui-form-label required"></label>
            <div class="layui-input-block">
                <input type="text" name="id" value="" class="layui-input">
            </div>
        </div>
        
        <div class="layui-form-item">
            <label class="layui-form-label required">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="userName" required lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入用户名" value="" class="layui-input">
            </div>
        </div> 
        <!--<div class="layui-form-item">
            <label class="layui-form-label required">密码</label>
            <div class="layui-input-block">
                <input type="text" name="password" required lay-verify="required" lay-reqtext="密码不能为空" placeholder="请输入密码" value="" class="layui-input">
            </div>
        </div> -->
        <div class="layui-form-item">
            <label class="layui-form-label ">身高</label>
            <div class="layui-input-block">
                <input type="text" name="height" required lay-verify="required" placeholder="请输入身高" value="" class="layui-input">
            </div>
        </div> 
        <div class="layui-form-item">
            <label class="layui-form-label ">体重</label>
            <div class="layui-input-block">
                <input type="text" name="weight" required lay-verify="required" placeholder="请输入体重" value="" class="layui-input">
            </div>
        </div> 
        <div class="layui-form-item">
            <label class="layui-form-label ">低血压值</label>
            <div class="layui-input-block">
                <input type="text" name="hypotensiveValue" required lay-verify="required" placeholder="请输入低血压值" value="" class="layui-input">
            </div>
        </div> 
        <div class="layui-form-item">
            <label class="layui-form-label ">高血压值</label>
            <div class="layui-input-block">
                <input type="text" name="hypertensiveValue" required lay-verify="required" placeholder="请输入高血压值" value="" class="layui-input">
            </div>
        </div> 
        <div class="layui-form-item">
            <label class="layui-form-label ">血糖值</label>
            <div class="layui-input-block">
                <input type="text" name="bloodGlucoseValue" required lay-verify="required" placeholder="请输入血糖值" value="" class="layui-input">
            </div>
        </div> 
        <div class="layui-form-item">
            <label class="layui-form-label ">血脂值</label>
            <div class="layui-input-block">
                <input type="text" name="bloodLipidValue" required lay-verify="required" placeholder="请输入血脂值" value="" class="layui-input">
            </div>
        </div> 
        <div class="layui-form-item">
            <label class="layui-form-label ">50米短跑完成秒数</label>
            <div class="layui-input-block">
                <input type="text" name="meterDashTime" required lay-verify="required" placeholder="请输入50米短跑完成秒数" value="" class="layui-input">
            </div>
        </div> 
        <div class="layui-form-item">
            <label class="layui-form-label ">引体向上次数</label>
            <div class="layui-input-block">
                <input type="text" name="pullUpTimes" required lay-verify="required" placeholder="请输入引体向上次数" value="" class="layui-input">
            </div>
        </div> 
        <div class="layui-form-item">
            <label class="layui-form-label ">俯卧撑次数</label>
            <div class="layui-input-block">
                <input type="text" name="pushUpTimes" required lay-verify="required" placeholder="请输入俯卧撑次数" value="" class="layui-input">
            </div>
        </div> 

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button id="submitButton" class="layui-btn layui-btn-normal" lay-submit lay-filter="save">确认保存</button>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use(['form', 'table'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            $ = layui.$;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        // userId
        let userId = $('#pageParam').val()
        if(userId){
            $.ajax({
                url: '/api/getUserById',
                type: 'GET',
                data: {id: userId},
                success: function(response){
                    form.val('userForm', response.data);
                    form.render();
                }
            });
        }

        //监听提交
        form.on('submit(save)', function (data) {
            var formData = data.field;
            layer.confirm('确定要修改吗?', {icon: 1, title: '提示'}, function (index) {
                $.ajax({
                    url: '/api/updateUser',
                    type: 'POST',
                    data: formData,
                    success: function (response) {
                        if (response.code == 0) {
                            layer.msg('修改成功!', {icon: 1});
                            layer.close(parentIndex);
                            table.reload('currentTableId');
                        } else {
                            layer.msg(response.msg, {icon: 2});
                        }
                    }
                });
            });
            return false;
        });
    });
</script>